﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xinkui.Entity.AutoGenerator;
using Xinkui.DataAccess.AutoGenerator;
using Xinkui.Common;

namespace Xinkui.WebModel.Cache {
    public static class CertificateCache {

        public static CompanyCertificate_Entity Get(int companyId, int certificateId) {
            var companyCertificateList = List(companyId);
            if (companyCertificateList != null) {
                return companyCertificateList.FirstOrDefault(u => u.CertID == certificateId);
            }
            else {
                return null;
            }
        }

        public static List<CompanyCertificate_Entity> List(int companyId) {
            return CacheProxy.Get<List<CompanyCertificate_Entity>>(SystemConst.CacheConst.GetCompanyCertificateKey(companyId), () =>
             {
                 return ListFromDb(companyId);
             });
        }

        public static List<CompanyCertificate_Entity> ListFromDb(int companyId) {

            return Singleton<CompanyCertificateDataAccess>.Instance.CompanyCertificate_ListByCompany(companyId);
        }

    }
}
